//@author A0086393U
package rightnow.util;

import java.io.IOException;
import java.net.URL;

import javafx.fxml.FXMLLoader;

/**
 * Utility class related to loading of fxml files.
 * 
 */
public class UiUtils {
	/**
	 * Loads the fxml file specifed at fxmlLocation and sets its
	 * root and controller to controllerClass. Used for custom component creation.
	 * 
	 * @param rootClass Class to be specified in fx:root
	 * @param controllerClass Class to be specified in fx:controller
	 * @param fxmlLocation URL location of the .fxml file to load
	 */
	public static void loadFxml(Object rootClass, Object controllerClass, 
													URL fxmlLocation) {
			FXMLLoader loader = new FXMLLoader(fxmlLocation);
			loader.setLocation(fxmlLocation);
			loader.setRoot(rootClass);
			loader.setController(controllerClass);
			
			try {
				loader.load();
			} catch (IOException ioe) {
				throw new RuntimeException(ioe);
			}
	}
}
